package com.ada.spark.rddoperator

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * 作用：过滤。返回一个新的RDD，该RDD由经过func函数计算后返回值为true的输入元素组成。
  */
object Spark07_filter {

    def main(args: Array[String]): Unit = {
        //创建SparkConf
        val conf = new SparkConf().setAppName("Spark07_filter").setMaster("local[*]")
        //创建Spark上下文对象
        val sc = new SparkContext(conf)

        val listRDD: RDD[Int] = sc.makeRDD(1 to 4)

        //按指定规则进行过滤
        val filterRDD: RDD[Int] = listRDD.filter(x => x % 2 == 0)

        println(filterRDD.collect().mkString(","))
        //2,4
    }

}
